Simulate Markov Chain Sequences

set.seed(77)
sequences <- simulate_sequences(
  states = 10,
  n_sequences = 100,
  seq_length = 25,
  learning_categories = "cognitive",
  use_learning_states = TRUE,
  na_range = 3:20
)

head(sequences, 10)
##            V1         V2         V3         V4         V5         V6         V7
## 1  Generalize  Interpret     Deduce   Abstract  Interpret Understand Understand
## 2      Deduce   Abstract     Deduce Understand Understand   Abstract     Deduce
## 3  Understand     Deduce   Abstract  Integrate  Integrate Understand   Abstract
## 4   Integrate  Interpret     Deduce Understand  Integrate   Memorize Understand
## 5  Categorize Understand  Integrate Understand Understand  Interpret Generalize
## 6  Generalize Generalize Categorize   Memorize   Memorize Generalize Understand
## 7  Generalize Categorize   Memorize Generalize Categorize   Abstract     Deduce
## 8  Generalize Generalize Understand     Deduce   Abstract Categorize Understand
## 9  Understand  Integrate Understand     Deduce   Abstract     Deduce   Abstract
## 10 Understand Understand   Abstract Categorize     Deduce Understand Understand
##            V8         V9        V10        V11        V12        V13        V14
## 1  Understand  Integrate  Integrate  Integrate     Deduce   Memorize Generalize
## 2  Understand  Integrate     Deduce  Interpret Generalize Categorize     Deduce
## 3      Deduce   Abstract Generalize   Abstract Categorize Categorize Generalize
## 4    Memorize Understand   Abstract Categorize  Integrate     Deduce   Memorize
## 5   Integrate     Deduce Understand  Integrate  Interpret Generalize   Abstract
## 6   Integrate Categorize Generalize Generalize  Interpret Categorize     Deduce
## 7  Understand   Abstract     Deduce Understand     Deduce   Abstract Understand
## 8   Integrate   Memorize   Memorize   Memorize     Deduce Understand Understand
## 9      Deduce Understand Categorize   Memorize Understand  Integrate   Abstract
## 10 Understand  Integrate Categorize  Integrate   Memorize   Abstract     Deduce
##           V15        V16        V17        V18        V19        V20        V21
## 1  Categorize Generalize Generalize  Interpret Categorize   Memorize Categorize
## 2  Understand Understand   Abstract Categorize     Deduce   Abstract     Deduce
## 3  Categorize Generalize  Integrate  Interpret Generalize Categorize   Memorize
## 4  Understand  Integrate  Interpret     Deduce Understand     Deduce Understand
## 5      Deduce   Abstract     Deduce   Abstract Categorize     Deduce  Interpret
## 6  Understand  Integrate Understand Understand Understand Understand   Abstract
## 7  Understand   Memorize Categorize   Memorize     Deduce Categorize     Deduce
## 8  Understand  Integrate Understand  Integrate Categorize     Deduce Understand
## 9      Deduce   Abstract   Memorize Generalize Categorize     Deduce   Memorize
## 10   Memorize  Integrate   Abstract     Deduce Understand  Integrate     Deduce
##           V22  V23  V24  V25
## 1   Integrate <NA> <NA> <NA>
## 2        <NA> <NA> <NA> <NA>
## 3        <NA> <NA> <NA> <NA>
## 4        <NA> <NA> <NA> <NA>
## 5        <NA> <NA> <NA> <NA>
## 6        <NA> <NA> <NA> <NA>
## 7        <NA> <NA> <NA> <NA>
## 8  Understand <NA> <NA> <NA>
## 9        <NA> <NA> <NA> <NA>
## 10       <NA> <NA> <NA> <NA>

Build TNA Model

model <- tna(sequences)
model
## State Labels : 
## 
##    Abstract, Categorize, Deduce, Generalize, Integrate, Interpret, Memorize, Understand 
## 
## Transition Probability Matrix :
## 
##              Abstract Categorize     Deduce Generalize  Integrate   Interpret
## Abstract   0.04230769 0.24230769 0.31923077 0.16923077 0.06153846 0.057692308
## Categorize 0.07042254 0.03286385 0.30046948 0.19718310 0.15492958 0.009389671
## Deduce     0.36619718 0.03169014 0.01056338 0.02464789 0.01760563 0.052816901
## Generalize 0.11808118 0.21771218 0.01845018 0.14760148 0.28413284 0.099630996
## Integrate  0.07492795 0.06340058 0.19020173 0.04034582 0.18155620 0.227665706
## Interpret  0.08974359 0.10256410 0.19871795 0.44230769 0.01923077 0.032051282
## Memorize   0.10924370 0.15126050 0.08403361 0.18487395 0.07563025 0.067226891
## Understand 0.12500000 0.05000000 0.08750000 0.01750000 0.33000000 0.025000000
##              Memorize Understand
## Abstract   0.04615385 0.06153846
## Categorize 0.16431925 0.07042254
## Deduce     0.05281690 0.44366197
## Generalize 0.00000000 0.11439114
## Integrate  0.09510086 0.12680115
## Interpret  0.02564103 0.08974359
## Memorize   0.10924370 0.21848739
## Understand 0.03750000 0.32750000
## 
## Initial Probabilities : 
## 
##   Abstract Categorize     Deduce Generalize  Integrate  Interpret   Memorize 
##       0.02       0.09       0.05       0.39       0.21       0.04       0.00 
## Understand 
##       0.20
PL <- plot(model)

from_tna (model)

Run Bootstrap with Same Seed

set.seed(2024)
tna_boot <- tna::bootstrap(model, iter = 1000)

splot(tna_boot)

set.seed(2024)

cograph_boot <- cograph::bootstrap(model, iter = 1000)


cograph_boot$ci_lower
##              Abstract Categorize      Deduce  Generalize  Integrate  Interpret
## Abstract   0.02082480 0.19259259 0.261990423 0.124987840 0.03383260 0.03161620
## Categorize 0.03864734 0.01351200 0.242987316 0.149745836 0.11108664 0.00000000
## Deduce     0.30669998 0.01111009 0.000000000 0.007376731 0.00359680 0.02748772
## Generalize 0.08068803 0.17151499 0.003890674 0.108685842 0.22518391 0.06474820
## Integrate  0.04877874 0.03845890 0.149852025 0.022983594 0.13411079 0.18204545
## Interpret  0.04999224 0.05732029 0.135772792 0.364223359 0.00000000 0.00684815
## Memorize   0.05404886 0.08849558 0.039670868 0.125000000 0.03197519 0.02518959
## Understand 0.09289084 0.03016212 0.060821721 0.005088414 0.28605755 0.01028212
##               Memorize Understand
## Abstract   0.022120904 0.03375409
## Categorize 0.116494019 0.04020044
## Deduce     0.028266063 0.38867676
## Generalize 0.000000000 0.07636294
## Integrate  0.061933318 0.09400585
## Interpret  0.005882353 0.04545455
## Memorize   0.053571429 0.14034678
## Understand 0.020725389 0.28381873
cograph_boot$ci_upper
##              Abstract Categorize     Deduce Generalize  Integrate  Interpret
## Abstract   0.06383179 0.29168547 0.37398374 0.21170182 0.09293896 0.08714745
## Categorize 0.10169492 0.05604207 0.36363636 0.25000000 0.20102798 0.02475555
## Deduce     0.42612825 0.05480874 0.02356902 0.04301164 0.03272876 0.07778501
## Generalize 0.15493231 0.27009012 0.03572071 0.18702898 0.33712341 0.13740697
## Integrate  0.10179641 0.09041697 0.23277033 0.05988323 0.22047345 0.27835554
## Interpret  0.13375908 0.15173538 0.26289286 0.52594572 0.04110298 0.06081081
## Memorize   0.17432306 0.21666667 0.13043478 0.25005252 0.12267071 0.11505276
## Understand 0.15700739 0.07162317 0.11980689 0.03315576 0.37559933 0.04177194
##              Memorize Understand
## Abstract   0.07143497 0.09231092
## Categorize 0.21393093 0.10331617
## Deduce     0.07850952 0.50174473
## Generalize 0.00000000 0.15451170
## Integrate  0.12816070 0.16321820
## Interpret  0.05224003 0.13815789
## Memorize   0.16380275 0.31194094
## Understand 0.05638215 0.36768229
cograph_boot$summary
##          from         to      weight     p_value   sig    cr_lower   cr_upper
## 1    Abstract   Abstract 0.042307692 0.345654346 FALSE 0.031730769 0.05288462
## 2  Categorize   Abstract 0.070422535 0.249750250 FALSE 0.052816901 0.08802817
## 3      Deduce   Abstract 0.366197183 0.002997003  TRUE 0.274647887 0.45774648
## 4  Generalize   Abstract 0.118081181 0.124875125 FALSE 0.088560886 0.14760148
## 5   Integrate   Abstract 0.074927954 0.191808192 FALSE 0.056195965 0.09365994
## 6   Interpret   Abstract 0.089743590 0.329670330 FALSE 0.067307692 0.11217949
## 7    Memorize   Abstract 0.109243697 0.372627373 FALSE 0.081932773 0.13655462
## 8  Understand   Abstract 0.125000000 0.057942058 FALSE 0.093750000 0.15625000
## 9    Abstract Categorize 0.242307692 0.016983017  TRUE 0.181730769 0.30288462
## 10 Categorize Categorize 0.032863850 0.468531469 FALSE 0.024647887 0.04107981
## 11     Deduce Categorize 0.031690141 0.457542458 FALSE 0.023767606 0.03961268
## 12 Generalize Categorize 0.217712177 0.028971029  TRUE 0.163284133 0.27214022
## 13  Integrate Categorize 0.063400576 0.229770230 FALSE 0.047550432 0.07925072
## 14  Interpret Categorize 0.102564103 0.296703297 FALSE 0.076923077 0.12820513
## 15   Memorize Categorize 0.151260504 0.232767233 FALSE 0.113445378 0.18907563
## 16 Understand Categorize 0.050000000 0.254745255 FALSE 0.037500000 0.06250000
## 17   Abstract     Deduce 0.319230769 0.005994006  TRUE 0.239423077 0.39903846
## 18 Categorize     Deduce 0.300469484 0.016983017  TRUE 0.225352113 0.37558685
## 19     Deduce     Deduce 0.010563380 0.738261738 FALSE 0.007922535 0.01320423
## 20 Generalize     Deduce 0.018450185 0.524475524 FALSE 0.013837638 0.02306273
## 21  Integrate     Deduce 0.190201729 0.019980020  TRUE 0.142651297 0.23775216
## 22  Interpret     Deduce 0.198717949 0.135864136 FALSE 0.149038462 0.24839744
## 23   Memorize     Deduce 0.084033613 0.357642358 FALSE 0.063025210 0.10504202
## 24 Understand     Deduce 0.087500000 0.140859141 FALSE 0.065625000 0.10937500
## 25   Abstract Generalize 0.169230769 0.055944056 FALSE 0.126923077 0.21153846
## 26 Categorize Generalize 0.197183099 0.058941059 FALSE 0.147887324 0.24647887
## 27     Deduce Generalize 0.024647887 0.502497502 FALSE 0.018485915 0.03080986
## 28 Generalize Generalize 0.147601476 0.064935065 FALSE 0.110701107 0.18450185
## 29  Integrate Generalize 0.040345821 0.298701299 FALSE 0.030259366 0.05043228
## 30  Interpret Generalize 0.442307692 0.003996004  TRUE 0.331730769 0.55288462
## 31   Memorize Generalize 0.184873950 0.141858142 FALSE 0.138655462 0.23109244
## 32 Understand Generalize 0.017500000 0.568431568 FALSE 0.013125000 0.02187500
## 33   Abstract  Integrate 0.061538462 0.269730270 FALSE 0.046153846 0.07692308
## 34 Categorize  Integrate 0.154929577 0.090909091 FALSE 0.116197183 0.19366197
## 35     Deduce  Integrate 0.017605634 0.527472527 FALSE 0.013204225 0.02200704
## 36 Generalize  Integrate 0.284132841 0.016983017  TRUE 0.213099631 0.35516605
## 37  Integrate  Integrate 0.181556196 0.044955045  TRUE 0.136167147 0.22694524
## 38  Interpret  Integrate 0.019230769 0.737262737 FALSE 0.014423077 0.02403846
## 39   Memorize  Integrate 0.075630252 0.416583417 FALSE 0.056722689 0.09453782
## 40 Understand  Integrate 0.330000000 0.000999001  TRUE 0.247500000 0.41250000
## 41   Abstract  Interpret 0.057692308 0.310689311 FALSE 0.043269231 0.07211538
## 42 Categorize  Interpret 0.009389671 0.743256743 FALSE 0.007042254 0.01173709
## 43     Deduce  Interpret 0.052816901 0.293706294 FALSE 0.039612676 0.06602113
## 44 Generalize  Interpret 0.099630996 0.184815185 FALSE 0.074723247 0.12453875
## 45  Integrate  Interpret 0.227665706 0.022977023  TRUE 0.170749280 0.28458213
## 46  Interpret  Interpret 0.032051282 0.529470529 FALSE 0.024038462 0.04006410
## 47   Memorize  Interpret 0.067226891 0.465534466 FALSE 0.050420168 0.08403361
## 48 Understand  Interpret 0.025000000 0.422577423 FALSE 0.018750000 0.03125000
## 49   Abstract   Memorize 0.046153846 0.340659341 FALSE 0.034615385 0.05769231
## 50 Categorize   Memorize 0.164319249 0.099900100 FALSE 0.123239437 0.20539906
## 51     Deduce   Memorize 0.052816901 0.319680320 FALSE 0.039612676 0.06602113
## 53  Integrate   Memorize 0.095100865 0.160839161 FALSE 0.071325648 0.11887608
## 54  Interpret   Memorize 0.025641026 0.592407592 FALSE 0.019230769 0.03205128
## 55   Memorize   Memorize 0.109243697 0.352647353 FALSE 0.081932773 0.13655462
## 56 Understand   Memorize 0.037500000 0.296703297 FALSE 0.028125000 0.04687500
## 57   Abstract Understand 0.061538462 0.296703297 FALSE 0.046153846 0.07692308
## 58 Categorize Understand 0.070422535 0.271728272 FALSE 0.052816901 0.08802817
## 59     Deduce Understand 0.443661972 0.000999001  TRUE 0.332746479 0.55457746
## 60 Generalize Understand 0.114391144 0.147852148 FALSE 0.085793358 0.14298893
## 61  Integrate Understand 0.126801153 0.074925075 FALSE 0.095100865 0.15850144
## 62  Interpret Understand 0.089743590 0.362637363 FALSE 0.067307692 0.11217949
## 63   Memorize Understand 0.218487395 0.192807193 FALSE 0.163865546 0.27310924
## 64 Understand Understand 0.327500000 0.000999001  TRUE 0.245625000 0.40937500
##       ci_lower   ci_upper
## 1  0.020824795 0.06383179
## 2  0.038647343 0.10169492
## 3  0.306699984 0.42612825
## 4  0.080688027 0.15493231
## 5  0.048778741 0.10179641
## 6  0.049992236 0.13375908
## 7  0.054048857 0.17432306
## 8  0.092890844 0.15700739
## 9  0.192592593 0.29168547
## 10 0.013511999 0.05604207
## 11 0.011110086 0.05480874
## 12 0.171514988 0.27009012
## 13 0.038458904 0.09041697
## 14 0.057320291 0.15173538
## 15 0.088495575 0.21666667
## 16 0.030162122 0.07162317
## 17 0.261990423 0.37398374
## 18 0.242987316 0.36363636
## 19 0.000000000 0.02356902
## 20 0.003890674 0.03572071
## 21 0.149852025 0.23277033
## 22 0.135772792 0.26289286
## 23 0.039670868 0.13043478
## 24 0.060821721 0.11980689
## 25 0.124987840 0.21170182
## 26 0.149745836 0.25000000
## 27 0.007376731 0.04301164
## 28 0.108685842 0.18702898
## 29 0.022983594 0.05988323
## 30 0.364223359 0.52594572
## 31 0.125000000 0.25005252
## 32 0.005088414 0.03315576
## 33 0.033832604 0.09293896
## 34 0.111086637 0.20102798
## 35 0.003596800 0.03272876
## 36 0.225183906 0.33712341
## 37 0.134110787 0.22047345
## 38 0.000000000 0.04110298
## 39 0.031975194 0.12267071
## 40 0.286057550 0.37559933
## 41 0.031616203 0.08714745
## 42 0.000000000 0.02475555
## 43 0.027487717 0.07778501
## 44 0.064748201 0.13740697
## 45 0.182045455 0.27835554
## 46 0.006848150 0.06081081
## 47 0.025189588 0.11505276
## 48 0.010282117 0.04177194
## 49 0.022120904 0.07143497
## 50 0.116494019 0.21393093
## 51 0.028266063 0.07850952
## 53 0.061933318 0.12816070
## 54 0.005882353 0.05224003
## 55 0.053571429 0.16380275
## 56 0.020725389 0.05638215
## 57 0.033754089 0.09231092
## 58 0.040200444 0.10331617
## 59 0.388676758 0.50174473
## 60 0.076362942 0.15451170
## 61 0.094005848 0.16321820
## 62 0.045454545 0.13815789
## 63 0.140346778 0.31194094
## 64 0.283818733 0.36768229
print(cograph_boot, type="sig")
## Bootstrap Analysis (stability, iter=1000)
## Significant edges: 13 / 63

Compare Significant Matrices

cat("Matrices identical:", identical(tna_boot$weights_sig, cograph_boot$weights_sig), "\n")
## Matrices identical: TRUE
cat("P-value correlation:", cor(c(tna_boot$p_values), c(cograph_boot$p_values)), "\n")
## P-value correlation: 1
cat("Max difference:", max(abs(tna_boot$weights_sig - cograph_boot$weights_sig)), "\n")
## Max difference: 0

Bootstrap Visualization (TNA-Matching Style)

The splot.tna_bootstrap() method produces TNA-matching visualizations:

# Default: TNA-style bootstrap plot
splot(cograph_boot, title = "Bootstrap Results (TNA Style)")

Display Modes

par(mfrow = c(2, 2))

# Styled: distinguishes sig/non-sig edges (default)
splot(cograph_boot, show = "styled", title = "Styled (default)")

# Significant only: shows only significant edges
splot(cograph_boot, show = "significant", title = "Significant Only")

# Full: all edges without styling
splot(cograph_boot, show = "full", title = "Full Network")

# CI mode: shows confidence interval bands
splot(cograph_boot, show = "ci", title = "With CI Bands")

Optional: Add Significance Stars

par(mfrow = c(1, 2))

# Default: no stars (TNA style)
splot(cograph_boot, title = "Default (no stars)")

# With stars: shows *, **, *** based on p-values
splot(cograph_boot, show_stars = TRUE, title = "With Significance Stars")

Customizing Significance Styling

par(mfrow = c(1, 2))

# Pink non-significant edges
splot(cograph_boot,
      color_nonsig = "pink",
      title = "Pink Non-Significant")

# Gray dotted non-significant edges
splot(cograph_boot,
      color_nonsig = "gray60",
      edge_style_nonsig = 3,  # dotted
      title = "Gray Dotted Non-Significant")

CI Bands Visualization

# CI bands show uncertainty - wider bands = more uncertainty
splot(cograph_boot,
      show_ci = TRUE,
      edge_ci_alpha = 0.25,
      title = "Bootstrap with CI Uncertainty Bands")

plot(tna_boot)

Summary Statistics

# Bootstrap summary
print(cograph_boot)
## Bootstrap Analysis (stability, iter=1000)
## Significant edges: 13 / 63
# Detailed edge-level results
head(cograph_boot$summary, 10)
##          from         to     weight     p_value   sig   cr_lower   cr_upper
## 1    Abstract   Abstract 0.04230769 0.345654346 FALSE 0.03173077 0.05288462
## 2  Categorize   Abstract 0.07042254 0.249750250 FALSE 0.05281690 0.08802817
## 3      Deduce   Abstract 0.36619718 0.002997003  TRUE 0.27464789 0.45774648
## 4  Generalize   Abstract 0.11808118 0.124875125 FALSE 0.08856089 0.14760148
## 5   Integrate   Abstract 0.07492795 0.191808192 FALSE 0.05619597 0.09365994
## 6   Interpret   Abstract 0.08974359 0.329670330 FALSE 0.06730769 0.11217949
## 7    Memorize   Abstract 0.10924370 0.372627373 FALSE 0.08193277 0.13655462
## 8  Understand   Abstract 0.12500000 0.057942058 FALSE 0.09375000 0.15625000
## 9    Abstract Categorize 0.24230769 0.016983017  TRUE 0.18173077 0.30288462
## 10 Categorize Categorize 0.03286385 0.468531469 FALSE 0.02464789 0.04107981
##      ci_lower   ci_upper
## 1  0.02082480 0.06383179
## 2  0.03864734 0.10169492
## 3  0.30669998 0.42612825
## 4  0.08068803 0.15493231
## 5  0.04877874 0.10179641
## 6  0.04999224 0.13375908
## 7  0.05404886 0.17432306
## 8  0.09289084 0.15700739
## 9  0.19259259 0.29168547
## 10 0.01351200 0.05604207